
proc createPlay {name parent args} {
	set play [Play #auto $args]
	[$parent getSequence] acquire $name $play
	return $play
}

proc createChapter {name parent args} {
	set chapter [Chapter #auto $args]
	$chapter setTitle $name
	[$parent getSequence] acquire $name $chapter
	return $chapter
}

proc createAct {name parent args} {
	set act [Act #auto $args]
	[$parent getSequence] acquire $name $act
	return $act	
}

proc createSketch {name parent args} {
	set sketch [Sketch #auto $args]
	[$parent getSequence] acquire $name $sketch
	return $sketch
}

proc createScene {name parent args} {
	set scene [Scene #auto $args]
	[$parent getSequence] acquire $name $scene
	return $scene	
}

proc includePart {name parent acts} {
	set part [[$acts getSequence] of $name]
	[$parent getSequence] set $name $part
	return
}

proc alterPart {name id parent acts} {
	set part [[[$acts getSequence] of $name] copy]
	[$parent getSequence] set $name$id $part
	return $part
}

proc valueAct {name acts} {
	set act [[$acts getSequence] of $name]
	set value {}
	foreach line [$act getAct] {
		set line [string trim $line]
		if {![string length $line]} continue
		if {![string length $value]} {
			set value $line
		} else {
			append value " $line"
		}
	} 
	return $value
}

proc pruneVariables {top chapters} {
	# First resolve all references.
	$top resolve {}
	foreach able [$top prune {}] {
		set chapter [string range $able 1 end]
		if {[[$chapters getSequence] has $chapter]} {
			$top updateAttributes [list $able $chapter]
		} else {
			inform "No definition for <$able>"
		}
	}
}
